package com.cneiu.ppms.common;

import com.cneiu.ppms.web.action.DepartmentController;
import com.cneiu.ppms.web.action.DocTemplateController;
import com.cneiu.ppms.web.action.GlobalParamController;
import com.cneiu.ppms.web.action.JobController;
import com.cneiu.ppms.web.action.LightBillController;
import com.cneiu.ppms.web.action.LightBillDetailController;
import com.cneiu.ppms.web.action.LineController;
import com.cneiu.ppms.web.action.MenuController;
import com.cneiu.ppms.web.action.MenuRoleController;
import com.cneiu.ppms.web.action.MeterController;
import com.cneiu.ppms.web.action.MeterMetricPointController;
import com.cneiu.ppms.web.action.MeterReadTypeController;
import com.cneiu.ppms.web.action.MetricPointController;
import com.cneiu.ppms.web.action.OrganizationController;
import com.cneiu.ppms.web.action.PeriodController;
import com.cneiu.ppms.web.action.PeriodDetailController;
import com.cneiu.ppms.web.action.PlanController;
import com.cneiu.ppms.web.action.PowerFactoryController;
import com.cneiu.ppms.web.action.PowerPlantController;
import com.cneiu.ppms.web.action.PowerPlantDocController;
import com.cneiu.ppms.web.action.PowerPlantLineController;
import com.cneiu.ppms.web.action.PowerPlantMetricPointController;
import com.cneiu.ppms.web.action.PowerPlantSubsController;
import com.cneiu.ppms.web.action.ReadController;
import com.cneiu.ppms.web.action.RoleAuthController;
import com.cneiu.ppms.web.action.RoleController;
import com.cneiu.ppms.web.action.RoleGroupController;
import com.cneiu.ppms.web.action.SectController;
import com.cneiu.ppms.web.action.SubstationController;
import com.cneiu.ppms.web.action.SysActionController;
import com.cneiu.ppms.web.action.TransController;
import com.cneiu.ppms.web.action.TransParamController;
import com.cneiu.ppms.web.action.UserController;
import com.cneiu.ppms.web.action.UserRoleController;
import com.cneiu.ppms.web.interceptor.SysInterceptor;
import com.cneiu.ppms.web.model.DepartmentModel;
import com.cneiu.ppms.web.model.DocTemplateModel;
import com.cneiu.ppms.web.model.GlobalParamModel;
import com.cneiu.ppms.web.model.JobModel;
import com.cneiu.ppms.web.model.LightBillDetailModel;
import com.cneiu.ppms.web.model.LightBillModel;
import com.cneiu.ppms.web.model.LineModel;
import com.cneiu.ppms.web.model.MenuModel;
import com.cneiu.ppms.web.model.MenuRoleModel;
import com.cneiu.ppms.web.model.MeterMetricPointModel;
import com.cneiu.ppms.web.model.MeterModel;
import com.cneiu.ppms.web.model.MeterReadTypeModel;
import com.cneiu.ppms.web.model.MetricPointModel;
import com.cneiu.ppms.web.model.OrganizationModel;
import com.cneiu.ppms.web.model.PeriodDetailModel;
import com.cneiu.ppms.web.model.PeriodModel;
import com.cneiu.ppms.web.model.PlanModel;
import com.cneiu.ppms.web.model.PowerFactoryModel;
import com.cneiu.ppms.web.model.PowerPlantDocModel;
import com.cneiu.ppms.web.model.PowerPlantLineModel;
import com.cneiu.ppms.web.model.PowerPlantMetricPointModel;
import com.cneiu.ppms.web.model.PowerPlantModel;
import com.cneiu.ppms.web.model.PowerPlantSubsModel;
import com.cneiu.ppms.web.model.PublicCodeModel;
import com.cneiu.ppms.web.model.ReadModel;
import com.cneiu.ppms.web.model.RoleAuthModel;
import com.cneiu.ppms.web.model.RoleGroupModel;
import com.cneiu.ppms.web.model.RoleModel;
import com.cneiu.ppms.web.model.SectModel;
import com.cneiu.ppms.web.model.SubstationModel;
import com.cneiu.ppms.web.model.TransModel;
import com.cneiu.ppms.web.model.SystemActionModel;
import com.cneiu.ppms.web.model.TransParamModel;
import com.cneiu.ppms.web.model.UserModel;
import com.cneiu.ppms.web.model.UserRoleModel;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.activerecord.CaseInsensitiveContainerFactory;
import com.jfinal.plugin.activerecord.dialect.OracleDialect;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

/**
 * API引导式配置
 * @author jiangli
 * @date 2013-04-15
 */
public class DefaultConfig extends JFinalConfig{

	/**
	 * 配置常量
	 */
	@Override
	public void configConstant(Constants me)
	{
		/** 必要配置，随后可用getProperty(...)获取值 **/
		loadPropertyFile("config.cfg");
		me.setDevMode(getPropertyToBoolean("SYS_DEVMODE", false));
		/** 设置视图类型为Jsp，否则默认为FreeMarker **/
		me.setViewType(ViewType.JSP);
		
	}

	/**
	 * 配置路由
	 */
	@Override
	public void configRoute(Routes me)
	{
		me.add("/system/commonCode", CommonController.class);
		me.add("/system/globalParam", GlobalParamController.class);
		me.add("/system/transParam", TransParamController.class);
		me.add("/system/powerFactory",PowerFactoryController.class);
		me.add("/users/user", UserController.class);
		me.add("/users/org", OrganizationController.class);
		me.add("/users/job", JobController.class);
		me.add("/users/dept", DepartmentController.class);
		me.add("/users/sysaction", SysActionController.class);
		me.add("/users/menu", MenuController.class);
		me.add("/users/menurole", MenuRoleController.class);
		me.add("/users/rolegroup", RoleGroupController.class);
		me.add("/users/role", RoleController.class);
		me.add("/users/userrole", UserRoleController.class);
		me.add("/users/roleauth", RoleAuthController.class);
		me.add("/users/lightbill", LightBillController.class);
		me.add("/users/lightbilldetail", LightBillDetailController.class);
		me.add("/users/period", PeriodController.class);
		me.add("/users/perioddetail", PeriodDetailController.class);
		me.add("/archive/power", PowerPlantController.class);
		me.add("/archive/powerdoc",PowerPlantDocController.class);
		me.add("/archive/doctemp",DocTemplateController.class);
		me.add("/archive/powersubs",PowerPlantSubsController.class);
		me.add("/archive/powerline",PowerPlantLineController.class);
		me.add("/archive/powermpoint",PowerPlantMetricPointController.class);
		me.add("/archive/meter", MeterController.class);
		me.add("/archive/meterreadtype", MeterReadTypeController.class);
		me.add("/archive/metermpoint", MeterMetricPointController.class);
		me.add("/archive/tran", TransController.class);
		me.add("/archive/subs", SubstationController.class);
		me.add("/archive/line", LineController.class);
		me.add("/archive/mpoint", MetricPointController.class);
		me.add("/meterread/read", ReadController.class);
		me.add("/meterread/plan", PlanController.class);
		me.add("/meterread/sect", SectController.class);
		
	}

	/**
	 * 配置插件
	 */
	@Override
	public void configPlugin(Plugins me) {
		/**Oracle数据库连接配置**/
		String jdbcUrl = getProperty("JDBC_URL").trim();
		String jdbcUser = getProperty("JDBC_USER").trim();
		String jdbcPawd = getProperty("JDBC_PASSWORD").trim();

		C3p0Plugin cp = new C3p0Plugin(jdbcUrl, jdbcUser, jdbcPawd);
		cp.setDriverClass("oracle.jdbc.driver.OracleDriver");
		me.add(cp);
		
		/**Oracle数据库ORM配置**/
		ActiveRecordPlugin arp = new ActiveRecordPlugin(cp);
		arp.setShowSql(true);
		me.add(arp);
		arp.setDialect(new OracleDialect());
		arp.setContainerFactory(new CaseInsensitiveContainerFactory());
		
		/**配置和数据库表的映射**/
		arp.addMapping("sup_code", PublicCodeModel.class);//公共编码
		arp.addMapping("sup_tran_std", TransParamModel.class);
		arp.addMapping("sup_config", GlobalParamModel.class);
		arp.addMapping("sup_pf_std", PowerFactoryModel.class);
		arp.addMapping("sa_user", UserModel.class);//用户
		arp.addMapping("sa_dept", DepartmentModel.class);//部门
		arp.addMapping("sa_job", JobModel.class);//岗位
		arp.addMapping("sa_org", OrganizationModel.class);//机构
		arp.addMapping("sa_sys_action", SystemActionModel.class);//用户权限
		arp.addMapping("sa_role_group", RoleGroupModel.class);//角色分组
		arp.addMapping("sa_role", RoleModel.class);//角色
		arp.addMapping("sa_user_auth", UserRoleModel.class);//用户角色
		arp.addMapping("sa_role_auth", RoleAuthModel.class);//角色权限
		arp.addMapping("sa_menu", MenuModel.class);//菜单
		arp.addMapping("sa_menu_role", MenuRoleModel.class);//菜单
		arp.addMapping("c_pp", PowerPlantModel.class);//电厂信息
		arp.addMapping("c_pp_doc", PowerPlantDocModel.class);
		arp.addMapping("sup_doc_template", DocTemplateModel.class);
		arp.addMapping("c_pp_mp", PowerPlantMetricPointModel.class);
		arp.addMapping("c_pp_subs", PowerPlantSubsModel.class);
		arp.addMapping("c_pp_line", PowerPlantLineModel.class);
		arp.addMapping("c_mp", MetricPointModel.class);//计量点
		arp.addMapping("c_meter", MeterModel.class);//电表
		arp.addMapping("c_meter_readtype", MeterReadTypeModel.class);//电表示数类型
		arp.addMapping("c_mp_meter_rela", MeterMetricPointModel.class);//电表计量点
		arp.addMapping("g_tran", TransModel.class);//变压器
		arp.addMapping("g_subs", SubstationModel.class);//变电站
		arp.addMapping("g_line", LineModel.class);//线路
		arp.addMapping("r_read", ReadModel.class);
		arp.addMapping("r_plan", PlanModel.class);
		arp.addMapping("r_sect", SectModel.class);
		arp.addMapping("sup_prc", LightBillModel.class);
		arp.addMapping("sup_prc_detail", LightBillDetailModel.class);
		arp.addMapping("sup_period", PeriodModel.class);
		arp.addMapping("sup_period_detail", PeriodDetailModel.class);
	}

	/**
	 * 配置全局拦截器
	 */
	@Override
	public void configInterceptor(Interceptors me){
		me.add(new SysInterceptor());            
	}

	/**
	 * 配置处理器
	 */
	@Override
	public void configHandler(Handlers me)
	{
	}

}
